/*
* yasl-qt (or simply yasl) is a qt-based program for symbian devices
* and intended to manage a shopping list.
* The acronym yasl stands for Yet Another Shopping List.
* 
* Copyright (C) 2011 - Alessandro Orlandi
* 
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QMenu>
#include <QMenuBar>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{

    ui->setupUi(this);
    ui->historyFilterEdit->setEnabled(false);
    ui->historyFilterEdit->setText("");


    mHideAction = new QAction( tr( "Hide" ), this );
    mHideAction->setSoftKeyRole(QAction::NegativeSoftKey);
    addAction( mHideAction );
    connect(mHideAction, SIGNAL(triggered()),
            this, SLOT(lower()));

    mOptionsAction = new QAction( tr( "Options" ), this );
    mOptionsAction->setSoftKeyRole(QAction::PositiveSoftKey);    
    addAction( mOptionsAction );

    QAction *lOptPurge = new QAction(tr("Purge"), 0);
    QAction *lOptSaveAll = new QAction(tr("Save all"), 0);
    QAction *lOptExit = new QAction(tr("Exit"), 0);

    //  START DEBUG Actions
    //  The following lines are useful to test/debug actions using the emulator
    //   because it does not have a "default" menu bar, so added action are not shown
    //   when PositiveSoftKey (i.e. the one on the bottom-left corner) is clicked

#if defined(Q_WS_S60)
    //do nothing
#else
    QMenu *lMainMenu = new QMenu();
    lMainMenu->addAction(lOptPurge);
    lMainMenu->addAction(lOptSaveAll);
    lMainMenu->addAction(lOptExit);
    mOptionsAction->setMenu(lMainMenu);
    this->menuBar()->addAction(mOptionsAction);
    connect(mOptionsAction, SIGNAL(triggered()), lMainMenu, SLOT(show()));
#endif
    //   END DEBUG

    this->menuBar()->addAction(lOptPurge);
    this->menuBar()->addAction(lOptSaveAll);
    this->menuBar()->addAction(lOptExit);

    connect(mOptionsAction, SIGNAL(triggered()),
            this->menuBar(), SLOT(show()));
    connect(lOptExit, SIGNAL(triggered()),
            this, SLOT(close()));
    connect(lOptSaveAll, SIGNAL(triggered()),
            ui->shoppingList,SLOT(saveShoppingList()));
    connect(lOptPurge, SIGNAL(triggered()),
            ui->shoppingList, SLOT(purgeShoppingList()));

    //Customize color
    this->setStyleSheet("QPushButton { color: cyan  }");

}

MainWindow::~MainWindow()
{
    delete ui;

}


